﻿namespace WMS6.Web.Billing
{
    using System;
    using System.Collections.Generic;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;

    public class StatementQuery : BasePage
    {
        protected Button btnExport;
        protected Button btnList;
        protected Button btnNew;
        protected Button btnSearch;
        protected DropDownList ddlBillingObject;
        protected DropDownList ddlBillingObjectDescr;
        protected DropDownList ddlBillingObjectID;
        protected DropDownList ddlDueFromTo;
        protected DropDownList ddlDueFromToescr;
        protected DropDownList ddlStatementID;
        protected DropDownList ddlStatus;
        protected DropDownList ddlStatusOper;
        protected HtmlForm F9200;
        protected HtmlInputHidden hdnActionID;
        protected HtmlHead Head1;
        protected Label lblBillingObject;
        protected Label lblBillingObjectID;
        protected Label lblDueFromTo;
        protected Label lblStatement;
        protected Label lblStatementID;
        protected Label lblStatus;
        protected HtmlLink mycss;
        protected ScriptManager ScriptManager1;
        protected TextBox txtBillingObjectID;
        protected TextBox txtStatementID;

        protected void btnList_Click(object sender, EventArgs e)
        {
            base.Server.Transfer(string.Format("StatementList.aspx?action={0}&from=list", base.UrlEncode(this.hdnActionID.Value.Trim())), false);
        }

        protected void btnSearch_Click(object sender, EventArgs e)
        {
            base.Server.Transfer("StatementList.aspx?action=" + this.hdnActionID.Value, false);
        }

        private void LoadDDl()
        {
            base.InitQueryDDL(this.ddlStatementID, 0);
            base.InitQueryDDL(this.ddlStatusOper, 0);
            base.InitQueryDDL(this.ddlBillingObjectID, 0);
            base.InitQueryDDL(this.ddlBillingObjectDescr, 0);
            base.InitQueryDDL(this.ddlDueFromToescr, 0);
            base.BindData2DDLBySysCode(this.ddlBillingObject, "BillingObject");
            base.BindData2DDLBySysCode(this.ddlDueFromTo, "DueFromTo");
            this.ddlBillingObject.Items.Insert(0, "");
            this.ddlDueFromTo.Items.Insert(0, "");
            if (!string.IsNullOrEmpty(base.Request.QueryString["from"]) && (base.Request.QueryString["from"] == "Invoice"))
            {
                List<WMS6.Web.CommonMethodServiceRef.SysCode4DDL> syscodeList = CommoneMethodServiceClientProxy.GetInstance().GetSysCodeDataSource("StatementStatu");
                for (int i = 0; i < syscodeList.Count; i++)
                {
                    if ((syscodeList[i].SysCodeValue == "New") || (syscodeList[i].SysCodeValue == "Closed"))
                    {
                        syscodeList.RemoveAt(i);
                        i--;
                    }
                }
                this.ddlStatus.DataSource = syscodeList;
                this.ddlStatus.DataTextField = "SysCodeText";
                this.ddlStatus.DataValueField = "SysCodeValue";
                this.ddlStatus.DataBind();
                this.ddlBillingObject.SelectedValue = base.Request.QueryString["BillingObject"];
                this.txtBillingObjectID.Text = base.Request.QueryString["BillingObjectID"];
                this.ddlDueFromTo.SelectedValue = base.Request.QueryString["DueFromTo"];
                this.ddlBillingObject.Enabled = false;
                this.txtBillingObjectID.Enabled = false;
                this.ddlDueFromTo.Enabled = false;
            }
            else
            {
                base.BindData2DDLBySysCode(this.ddlStatus, "StatementStatu");
                this.ddlStatus.Items.Insert(0, "");
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                this.LoadDDl();
            }
        }

        public string BillingObject
        {
            get
            {
                if (!string.IsNullOrEmpty(this.ddlBillingObject.Text.Trim()))
                {
                    return base.GetParamsString(this.ddlBillingObject.Text.Trim(), this.ddlBillingObjectDescr.SelectedValue);
                }
                return "";
            }
        }

        public string BillingObjectID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtBillingObjectID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtBillingObjectID.Text.Trim(), this.ddlBillingObjectID.SelectedValue);
                }
                return "";
            }
        }

        public string DueFromTo
        {
            get
            {
                if (!string.IsNullOrEmpty(this.ddlDueFromTo.Text.Trim()))
                {
                    return base.GetParamsString(this.ddlDueFromTo.Text.Trim(), this.ddlDueFromToescr.SelectedValue);
                }
                return "";
            }
        }

        public string StatementID
        {
            get
            {
                if (!string.IsNullOrEmpty(this.txtStatementID.Text.Trim()))
                {
                    return base.GetParamsString(this.txtStatementID.Text.Trim(), this.ddlStatementID.SelectedValue);
                }
                return "";
            }
        }

        public string Status
        {
            get
            {
                if (!string.IsNullOrEmpty(this.ddlStatus.SelectedValue.Trim()))
                {
                    return base.GetParamsString(this.ddlStatus.SelectedValue.Trim(), this.ddlStatusOper.SelectedValue);
                }
                return "";
            }
        }
    }
}

